/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.composite.editpart;

import org.eclipse.draw2d.ConnectionLayer;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ShortestPathConnectionRouter;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.LayerConstants;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.editpart.DiagramEditPart;
import com.cea.papyrus.core.editpart.IUMLDiagramElementEditPart;
import com.cea.papyrus.diagraminterchange2.di2.Diagram;

/**
 * Controller for a Composite diagram 
 */
public class CompositeDiagramEditPart extends DiagramEditPart
implements LayerConstants, IUMLDiagramElementEditPart {

	/**
	 * Creates a new CompositeDiagramEditPart.
	 * @param diagram the diagram controlled by this edit part
	 * @param modelManager the model manager associated to the editor
	 */
	public CompositeDiagramEditPart(Diagram diagram,ModelManager modelManager) {
		super(diagram,modelManager);

	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.common.editpart.DiagramEditPart#createEditPolicies()
	 */
	@Override
	protected void createEditPolicies(){
		super.createEditPolicies();
        // overload the GRAPHICAL_NODE_ROLE editPolicy to use the diagram specific one
        installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new GraphNodeEditPolicy() );
        // other EditPolicies
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new CompositeLayoutEditPolicy(
				(XYLayout)getContentPane().getLayoutManager()));

	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.common.editpart.DiagramEditPart#createFigure()
	 */
	@Override
	protected IFigure createFigure() {
		IFigure f = super.createFigure();
		ConnectionLayer connLayer = (ConnectionLayer)getLayer(LayerConstants.CONNECTION_LAYER);
		connLayer.setConnectionRouter(new ShortestPathConnectionRouter(f));		
		return f;
	}




}
